package com.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Vector;

public class ExerciseSell {

    public static void main(String[] args) throws InterruptedException {
        TickWindow tickWindow=new TickWindow(1000);

        List<Integer> amountList=new Vector<>();

        List<Thread> threadList=new ArrayList<>();

        for (int i = 0; i < 2000; i++) {
           Thread thread=new Thread(()->{
               //买票
               try {
                   Thread.sleep(100);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
               int sells = tickWindow.sell(1);
               amountList.add(sells);
           }) ;

           threadList.add(thread);
           thread.start();
        }

        for (Thread thread : threadList) {
         thread.join();
        }
        System.out.println("卖出"+amountList.stream().mapToInt(i->i).sum());
        System.out.println("剩余"+tickWindow.getCount());

    }


    static Random random=new Random();
    public static int randomAmount(){return random.nextInt(2)+1;}

}
